<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>Spring登录</title>
    <script type="text/javascript">
        <%--function showMsg() {--%>
        <%--    var msg = '${msg}';--%>
        <%--    if(msg != null && msg != "" && msg != "null" && msg != '') {--%>
        <%--        alert(msg);--%>
        <%--    }--%>
        <%--    console.log(msg)--%>
        <%--}--%>
        function directIndex() {
            location.replace("index.jsp");
        }
        //通过js实现登录验证码
        var code;
        function createCode() {
            code = "";
            var codeLength = 4;
            var checkCode = document.getElementById("checkCode");
            var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
                'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
            for(var i=0; i < codeLength; i++) {
                var charNum = Math.floor(Math.random() * 52)
                code += codeChars[charNum];
            }
            if(checkCode) {
                checkCode.className = "code";
                checkCode.innerHTML = code;
            }
        }
        function validateCode() {
            var inputCode = document.getElementById("inputCode").value;
            if(inputCode.length <= 0) {
                alert("请输入验证码");
            }else if(inputCode.toUpperCase() != code.toUpperCase()) {
                alert("验证码输入有误！");
                createCode();
            }else {
                alert("验证码正确");
                var msg = '${msg}';
                alert(msg);
            }
        }
    </script>
</head>
<body onload="createCode()">

<form action="/zxq/admin/login.do" method="post">
    用户名：
    <input type="text" name="username">
    <br>
    密 码：
    <input type="password" name="password">
    <br>
    <div class="code" id="checkCode" onclick="createCode()"></div>
    <a href="#" onclick="createCode()">看不清换一张</a>
    验证码：<br>
    <input type="text" id="inputCode">
    <input type="submit" onclick="validateCode()" value="登录"/>
<%--    <input type="url" value="注册">--%>
    <input type="reset" value="重置"/>
    <br>

</form>
返回主页面
<button onclick="directIndex()">返回主页</button>
</body>
</html>